#!/usr/bin/perl -w
use DBI;
 
our $db = "trancode";
our $host = "192.168.1.109";
our $user = "root";
our $pwd = "root";
local $connection;
local $dbconn;

sub my_connect {
	$connection="dbi:mysql:$db:$host";
	$dbconn = DBI->connect($connection,$user,$pwd, { RaiseError => 1 }) or die "failed to connect mysql,$!";
}


sub my_disconnect {
    $dbconn->disconnect();
}

sub set_task_work_status {

	$p_rowid = shift||"";
	$p_status = shift||"";
	$p_scomment = shift||"";

	if($p_rowid eq "") {

		return 0;
	}

	$sth1=$dbconn->prepare("update t_task set status = ?, scomment = ?  where tid = ?");
        $sth1->execute($p_status, $p_scomment, $p_rowid);	
	return 1;
}


sub update_task_field {

	$p_rowid = shift||"";
	$p_field = shift||"";
	$p_value = shift||"";

	if($p_rowid eq "" || $p_field eq "" || $p_value eq "") {

		return 0;
	}

	$sth1=$dbconn->prepare("update t_task set $p_field = ?  where tid = ?");
        $sth1->execute($p_value, $p_rowid);	
	return 1;
}

sub set_analyize_end_status {

	$rowid = shift||"";
        if($rowid eq "") {

                return 0;
        }

        $sth1=$dbconn->prepare("update t_task set status = 'error', scomment = 'format is error'  where status = 'analyize' and (vcode is null or acode is null or length(vcode) < 3 or length(acode)<3 ) and tid = ?");
        $sth1->execute($rowid);
	#upload --> analyize-->prepare-->split-->trancode-->merage-->down;
        $sth1=$dbconn->prepare("update t_task set status = 'prepare', scomment = 'waiting split'  where status = 'analyize' and (vcode is not null and acode is not null and length(vcode) >2 and length(acode) > 2 ) and tid = ?");
        $sth1->execute($rowid);
	
}

1;
